package com.zzs.team.Controller;

import com.zzs.team.Entity.TeamShow;
import com.zzs.team.Service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
public class ReservationController {

    @Autowired
    private ReservationService reservationService;

    @PostMapping("/reservation/addReservation")
    public Map addReservation(String userid,Integer teamid){
        System.out.println("userid:"+userid+"  teamid:"+teamid);
        Map result = new HashMap();
        try{
            Map map = reservationService.addReservation(userid, teamid);
            result.put("msg",map.get("msg"));    //预约成功返回1 人数满了返回0
            result.put("hasNumber",map.get("hasNumber"));
        }catch (Exception e){
            e.printStackTrace();
            result.put("msg",-1);   //失败返回-1
        }
        return result;
    }

    @PostMapping("/reservation/cancleReservation")
    public Map cancleReservation(String userid,Integer teamid){
        Map map = new HashMap();
        try {
            Map map1 = reservationService.cancleReservation(userid, teamid);
            map.put("msg",map1.get("msg"));
            map.put("hasNumber",map1.get("hasNumber"));
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg",0);
        }
        return map;
    }

    @PostMapping("/reservation/getUserReservationsTeamShow")
    public Map getUserReservations(String userID){
        Map map = new HashMap();
        try {
            List<TeamShow> reservations = reservationService.getUserReservationsTeamShow(userID);
            map.put("reservations",reservations);
            map.put("msg",1);
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg",0);
        }
        return map;
    }
}
